import json

import requests


class RequestsHandler:

    def __init__(self):
        '''初始化方法'''
        self.session = requests.session()

    def visit(self, method, url, params=None, data=None, json=None, headers=None, **kwargs):
        result = self.session.request(method, url, params=params, data=data, json=json, headers=headers, **kwargs)
        try:
            # 返回json结果
            return result.json()
        except Exception:
            return 'not json'

    def close_session(self):
        self.session.close()

# if __name__ == '__main__':
